package GUI;

import swimming.VIPcard;

import use.consumeuse;
import use.VIPuse;
import use.consumptionuse;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class recharge {
    private JPanel panel1;
    private JTextField TextField;
    private JTextField textField1;
    private JButton 确定Button;
    private JButton 会员卡充值Button;
    private JButton 新会员注册Button;
    private JButton 查询修改会员信息Button;
    private JButton 更改系统密码Button;
    private JButton 查询消费记录Button;
    private JButton 会员卡汇总记录Button;
    private JButton 使用会员卡Button;
    private JButton 消费记录报表Button;

    public static void iface()
    {
        JFrame frame = new JFrame("游泳馆会员管理系统");
        frame.setSize(500, 400);
        frame.setLocation(400, 200);

        recharge t1 = new recharge();
        frame.add(t1.panel1);

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public recharge()   {
        会员卡充值Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new recharge().iface();
            }
        });
        查询消费记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new consume().iface();
            }
        });
        查询修改会员信息Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new revise().iface();
            }
        });
        更改系统密码Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new password().iface();
            }
        });
        新会员注册Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new VIP().iface();
            }
        });
        会员卡汇总记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new totalVIP().iface();
            }
        });
        使用会员卡Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new usecard().iface();
            }
        });
        确定Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                VIPuse vip=new VIPuse();
                consumptionuse co=new consumptionuse();
                consumeuse cos=new consumeuse();
                List<?> state;
                String[] a=new String[2];
                String[] b=new String[4];
                String[] c=new String[3];
                a[0]=TextField.getText();
                a[1]=textField1.getText();
                b[0]=TextField.getText();
                Calendar calendar = Calendar.getInstance();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                b[2]=formatter.format(calendar.getTime());
               // b[2]=timetext.getText();
                b[3]=textField1.getText();
                String q=null;
                String w=null;
                try {
                    List<VIPcard> list1= vip.搜索(a[1]);
                    for (VIPcard v : list1) {
                        //q=v.getCardnum();
                        q=v.getCardtype();
                        w=v.getState();
                    }
                    if(q.equals("折扣卡"))
                    {
                        JOptionPane.showMessageDialog(null, "折扣卡无法储值", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
                    else if(w.equals("禁用"))
                    {
                        JOptionPane.showMessageDialog(null, "该卡已被禁用，暂时无法使用", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
                    else{
                        list1= (List<VIPcard>) vip.修改money(a);
                        for (VIPcard v : list1) {
                            b[1]= v.getMoney();
                        }
                        state=co.会员卡充值(b);
                        if(state == null)
                        {
                            JOptionPane.showMessageDialog(null, "非营业时间", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                        }
                        else {
                            JOptionPane.showMessageDialog(null, "充值成功", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                        }
                        c[0]=textField1.getText();
                        //c[2]=timetext.getText();
                        c[1]=formatter.format(calendar.getTime());
                        c[2]="0";
                        cos.增加(c);
                    }
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        });
        消费记录报表Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new baobiao().iface();
            }
        });
    }

    public static void main(String[] args) {
        iface();
    }
}
